import { Injectable } from '@angular/core';
import { Events } from 'ionic-angular';
/*
  Generated class for the EventProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class EventProvider {

	public EVENT_LOGIN = "eventLogin";
	public EVENT_CENTER = "eventCenter";
	public EVENT_AFTER_LOGIN = "eventAfterLogin";
	public EVENT_AFTER_ORDERS = "eventAfterOrders";
	public EVENT_PROGRESS_VALUE = "eventProgressValue";
	
	constructor(public events: Events) {
		console.log('Hello EventProvider Provider');
	}

	/**
	 * 注册事件 the event handler（订阅消息）
	 */
	public bindEvents(name: string, handler: any) {
		this.events.subscribe(name, handler);
	}

	/**
	 * 响应事件 （取消订阅） 
	 */
	public unbindEvents(name: string, handler: any) {
		let fal = this.events.unsubscribe(name, handler);
		console.log("unbindEvents:"+fal);
	}

	/**
	 * 响应事件 （发布订阅）
	 */
	public sendEvents(name: string, data: any) {
		this.events.publish(name, data);
	}

}